import Vue from 'vue'
import App from './App.vue'
import router from './router'
//按需引入
// import './plugins/element.js'
//全局引入
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);

//导入富文本编辑器
import VueQuillEditor from 'vue-quill-editor'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
Vue.use(VueQuillEditor)

//导入全局样式表
import  './assets/css/global.css'
//导入字体图标
import './assets/fonts/iconfont.css'

//导入进度条:js和css
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

import axios from 'axios'
Vue.prototype.$http = axios

//导入树形表格
import TreeTable from 'vue-table-with-tree-grid'
Vue.component('tree-table',TreeTable)

//配置请求的根路径
// axios.defaults.baseURL='http://127.0.0.1:8088/api/private/v1/'
axios.defaults.baseURL='http://127.0.0.1:8888/api/private/v1/'
Vue.config.productionTip = false

//定义全局过滤器，用来格式化时间
Vue.filter('dateFormat',function (originVal) {
  const dt = new Date(originVal)

  const y = dt.getFullYear()
  //padStart(2,'0')，不足两位用零填充
  const m = (dt.getMonth()+1+'').padStart(2,'0')
  const d = (dt.getDate()+'').padStart(2,'0')
  const hh = (dt.getHours()+'').padStart(2,'0')
  const mm = (dt.getMinutes()+'').padStart(2,'0')
  const ss = (dt.getSeconds()+'').padStart(2,'0')
  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})


//通过给axios请求拦截器添加token，保证拥有获取数据的权限(重要)
//config里打印出来可以发现有headers属性

//在request拦截器中，展示进度条NProgress.start()，在页面最上面，进行访问时，会自动生成进度条
//在response拦截器中，隐藏进度条NProgress.done()
axios.interceptors.request.use(config => {
  // console.log(config)
  //将token值保存到Authorization中
  config.headers.Authorization = window.sessionStorage.getItem('token')
  //展示进度条
  NProgress.start()
  //在最后必须return config
  return config
})
axios.interceptors.response.use(config => {
  // console.log(config)
  //结束进度条
  NProgress.done()
  //在最后必须return config
  return config
})

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
